/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pos.domain;

import com.pos.collection.util.CollectionUtils;
import java.io.Serializable;
import java.util.Collections;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 *
 * @author suraj
 */
@Entity
@Table(name = "salesDetails")
public class SalesDetail extends ItemTransaction implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long billNumber;
    @OneToOne
    private Customer customer;
    @OneToMany(cascade = CascadeType.ALL)
    private Set<SaleLineItem> lineItems = CollectionUtils.newHashSet();

    public SalesDetail() {
        this.customer = new Customer();
    }

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public long getBillNumber() {
        return billNumber;
    }

    public void setBillNumber(long billNumber) {
        this.billNumber = billNumber;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final SalesDetail other = (SalesDetail) obj;
        if (this.billNumber != other.billNumber) {
            return false;
        }
        if (this.customer != other.customer && (this.customer == null || !this.customer.equals(other.customer))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 71 * hash + (int) (this.billNumber ^ (this.billNumber >>> 32));
        hash = 71 * hash + (this.customer != null ? this.customer.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return String.valueOf(this.billNumber);
    }

    @Override
    public Set getLineItems() {
        return Collections.unmodifiableSet(lineItems);
    }

    @Override
    public void addItem(LineItem item) {
        this.lineItems.add((SaleLineItem) item);
    }
}
